home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Periodicals / develop / develop 4 code / IIgs Printer Driver / DIALOG.ASM < prev    next >
Encoding:
Assembly Source File  |  1990-08-20  |  36.7 KB  |  1,013 lines  |  [TEXT/pdos]

  1. *****************************************************************************
  2. *
  3. *       Apple IIgs New Printer Driver
  4. *
  5. *       File: dialog.asm --
  6. *             Doing dialog boxes, thereby modifying user's print record
  7. *
  8. *       Written by Ben Koning                                                 
  9. *       Modified by Matt Deatherage
  10. *       Copyright (C) 1990 Apple Computer, Inc.                               
  11. *
  12. *****************************************************************************
  13.  
  14.  
  15.              mcopy dialog.macros
  16.              copy  drvrequates.asm
  17.              copy  2/ainclude/e16.window
  18.              copy  2/ainclude/e16.control
  19.  
  20. *
  21. *STATUS MESSAGE ROUTINES:
  22. *StartStatusMessage/FinishStatusMessage/StatusMessage/StatusManFeedPrompt
  23. *These routines can display messages for the user.  After calling
  24. *StartStatusMessage, calling StatusMessage with ParamLongA pointing to a
  25. *string will cause that string to be shown, centered, in a centered dialog
  26. *box (640/320 mode automatically taken care of).  StatusManFeedPrompt will
  27. *put up a caution alert asking the user to insert the next sheet, to be
  28. *numbered with the value given in ParamWordA.  Call FinishStatusMessage when
  29. *done, erasing the dialog box.
  30. *
  31.  
  32. *
  33. *STARTSTATUSMESSAGE: Draw box used by "StatusMessage"; calc to prepare for
  34. *"StatusMesgFeedPrompt":
  35. *
  36. StartStatusMessage START
  37.             USING  PicterData
  38.  
  39.             _WaitCursor          ;put up wait cursor
  40.  
  41. * modify the dialog coordinates
  42.  
  43.             lda    StatusWindowCoordX2
  44.             sec
  45.             sbc    StatusWindowCoordX1  ;calc size (silly at runtime)
  46.             sta    StatusWindowWidth    ;save size
  47.             pha                         ;result space for scb
  48.             _GetMasterSCB
  49.             pla
  50.             ldx    #640                 ;assume 640 mode for a sec
  51.             and    #$80                 ;look at mode bit (1=640, 0=320)
  52.             bne    StMeMode640
  53.             ldx    #320                 ;change assumption made above
  54. StMeMode640 txa
  55.             sec
  56.             sbc    StatusWindowWidth    ;acc now has [320|640] - (X2-X1)
  57.             lsr    a                    ;divide by two
  58.             sta    StatusWindowCoordX1  ;this is left coordinate of box
  59.             sta    ManFeedAlertTempCoordX1 ;also for man feed alert template
  60.             clc
  61.             adc    StatusWindowWidth    ;maintain proper size of box
  62.             sta    StatusWindowCoordX2  ;this is right coordinate of box
  63.             sta    ManFeedAlertTempCoordX2 ;also for man feed alert template
  64.  
  65.             pha                          ;result space for window grafport...
  66.             pha
  67.             pushlong #StatusWindowTemp  ;draw window from template
  68.             _NewWindow                  ;this does NOT set current grafport!
  69.             pulllong StatusWindowPtr    ;save our ticket to access the box
  70.             lda    #1                   ;indicate it's ok to use it now
  71.             sta    StatusWindowExists
  72.             rts
  73.  
  74.             END
  75. *
  76. *FINISHSTATUSMESSAGE: Removes the box displayed above; won't crash if called
  77. *alone; normal cursor:
  78. *
  79.  
  80. FinishStatusMessage START
  81.             USING  PicterData
  82.  
  83.             lda StatusWindowExists   ;was it ever really drawn?
  84.             beq    FiStExit             ;if not, don't do CloseWindow
  85.             pushlong StatusWindowPtr    ;erase window and dispose memory
  86.             _CloseWindow
  87.             _InitCursor                 ;remove wait cursor
  88.             stz    StatusWindowExists   ;it's gone now
  89. FiStExit    rts
  90.  
  91.             END
  92. *
  93. *STATUSMESSAGE: Draws centered string at "ParamLongA" into above-opened
  94. *message box; uninit-proof:
  95. *
  96.  
  97. StatusMessage START
  98.             USING  PicterData
  99.  
  100.             lda  StatusWindowExists   ;was window ever drawn?
  101.             beq    StMeExit             ;if not, abort this routine
  102.             pha                         ;result space...
  103.             pha
  104.             _GetPort                    ;save old grafport on stack
  105.             pushlong StatusWindowPtr    ;set grafport to box's port...
  106.             _SetPort
  107.             pushlong #StMeBigRect       ;clear box contents...
  108.             _EraseRect
  109.             pha                         ;result space
  110.             pushlong ParamLongA         ;push pointer to our messgae
  111.             _StringWidth                ;ask what size it will be
  112.             lda    StatusWindowWidth    ;leave result on stack
  113.             sec                         ;for subtract right on the stack
  114.             sbc    1,s                  ;acc now has (X2-X1) - width
  115.             lsr    a                    ;divide by two; acc now has X coord
  116.             sta    1,s                  ;this is start X coordinate for text
  117.             pushword StatusWindowTextY  ;this is start Y coordinate for text
  118.             _MoveTo                     ;move the pen to pushed coordinates
  119.             pushlong ParamLongA         ;and draw the string...
  120.             _DrawString
  121.             _SetPort                    ;restore old grafport from stack
  122. StMeExit    rts
  123.  
  124. *Big rectangle to clear status box contents:
  125. StMeBigRect dc     i2'0,0,200,320'
  126.  
  127.             END
  128.  
  129.  
  130.  
  131. *
  132. *STATUSMESGFEEDPROMPT: Prompts to insert "ParamWordA"-th page; call after
  133. *"StartStatusMessage":  This routine exits with carry set if cancel option was
  134. *selected by user.
  135. *
  136.  
  137. StatusMesgFeedPrompt START
  138.             USING PicterData
  139.  
  140.             lda StatusWindowExists
  141.             beq    StFeExit
  142.             pushword ParamWordA         ;int to be converted to string
  143.             pushlong #ManFeedAlertTempPageNo ;where number ascii data goes
  144.             pushword #5                 ;length
  145.             pushword #0                 ;unsigned
  146.             _Int2Dec                    ;convert and store it
  147.             pha                         ;result space
  148.             pushlong #ManFeedAlertTemp  ;template
  149.             pushlong #0                 ;no filter proc
  150.             _NoteAlert
  151.             pla                         ;get item id that was selected
  152.             cmp    #mesgFeedPromptNGButtID ;set carry only if cancel selected
  153.             beq    StFeExit
  154.             clc
  155. StFeExit    rts
  156.  
  157.             END
  158. *
  159. *NOTCORRECTDEVDIALOG: Displays message about correct printer not being
  160. *connected; call anytime:
  161. *
  162. NotCorrectDevDialog START
  163.             USING  PicterData
  164.  
  165.             lda DevAlertTempCoordX2  ;modify dialog coordinates...
  166.             sec
  167.             sbc    DevAlertTempCoordX1  ;calc size (silly at runtime)
  168.             sta    NoCoDiXSize          ;save size
  169.             pha                         ;result space for scb
  170.             _GetMasterSCB
  171.             pla
  172.             ldx    #640                 ;assume 640 mode for a sec
  173.             and    #$80                 ;look at mode bit (1=640, 0=320)
  174.             bne    NoCoDiMode640
  175.             ldx    #320                 ;change assumption made above
  176. NoCoDiMode640 txa
  177.             sec
  178.             sbc    NoCoDiXSize          ;acc now has [320|640] - (X2-X1)
  179.             lsr    a                    ;divide by two
  180.             sta    DevAlertTempCoordX1  ;this is left coordinate of box
  181.             clc
  182.             adc    NoCoDiXSize          ;maintain proper X size of box
  183.             sta    DevAlertTempCoordX2  ;this is right coordinate of box
  184.             pha                         ;result space
  185.             pushlong #DevAlertTemp      ;template
  186.             pushlong #0                 ;no filter proc
  187.             _NoteAlert                  ;do the dialog until button hit
  188.             pla                         ;we don't care about which item hit
  189.             rts
  190. *For calculating horizontally centered/sized box:
  191. NoCoDiXSize dc     i2'0'
  192.  
  193.             END
  194. *
  195. *CONDUCT-DIALOG-ROUTINES: These routines handle the dialog boxes for
  196. *gathering the information to modify the print record.
  197. *
  198.  
  199.  
  200. *
  201. *CONDUCTSTYLEDIALOG: Does Start/FinishDialog/TaskMaster, does metrics
  202. *routines to change print record. On exit, accumulator is set/cleared
  203. *depending on OK/Cancel selection:
  204. *
  205. *Modify dialog data to reflect settings of current print record:  This would
  206. *be much more elegant if only the dialog ID's could be the same as the data in
  207. *the print record...
  208.  
  209. ConductStyleDialog START
  210.             USING  PicterData
  211.  
  212.             jsr GetOutputPortName     ;fill-in "Printer/Port" string
  213.  
  214.             jsr    GetPaper
  215.             clc
  216.             adc    #paperTypeUSALtrItemID    ;convert id # to dialog id
  217.             sta    paperTypeInitValue
  218. *
  219.             jsr    GetReduction
  220.             clc
  221.             adc    #reductionFullSizeItemID  ;convert to dialog id
  222.             sta    reductionInitValue
  223. *
  224.             stz    effectsNoGapsInitValue
  225.             jsr    GetPageGap
  226.             beq    CoStNext1
  227.             lda    #1
  228.             sta    effectsNoGapsInitValue
  229. *
  230. CoStNext1   stz    effectsCondensedInitValue
  231.             jsr    GetVSize
  232.             beq    CoStNext2
  233.             lda    #1
  234.             sta    effectsCondensedInitValue
  235.  
  236. CoStNext2   jsr    GetOrientation
  237.             sta    CoStOrientationState        ;we do this ourselves
  238.  
  239. *Now go draw the window with all the controls:
  240.  
  241.             lda    #StyleControlTemp    ;get address of control template
  242.             sta    ParamLongA+0         ;list for this dialog box
  243.             lda    #StyleControlTemp|-16
  244.             sta    ParamLongA+2
  245.             jsr    StartDialog          ;draw dialog window and controls
  246.  
  247. *Setup our TaskMask to handle keyboard events:
  248.             lda    #DialogTaskMaskYesKeys|-16     ;need change hi word only
  249.             sta    DialogTaskMask+2
  250.  
  251. *Take events until OK or CANCEL:
  252. CoStEventLoop pha                       ;result space
  253.             pushword #$FFFF             ;event mask for taskmaster
  254.             pushlong #DialogTaskRecord  ;where to stuff event data
  255.             _TaskMaster                 ;go handle events in window
  256.             pla                         ;get result code
  257.  
  258. *Redraw ctls for update evt.  Rely on at least 1 update event @ first to
  259. *invert apt port/land icon:
  260.             cmp    #6                   ;update event?
  261.             beq    CoStIsUpdate1
  262.             brl    CoStNotUpdate
  263. CoStIsUpdate1 ldx  DialogWindowPtr+0    ;check it's our window
  264.             cpx    DialogTaskData+0
  265.             beq    CoStIsUpdate2
  266.             brl    CoStNotUpdate
  267. CoStIsUpdate2 ldy  DialogWindowPtr+2
  268.             cpy    DialogTaskData+2
  269.             beq    CoStIsUpdate3
  270.             brl    CoStNotUpdate
  271. CoStIsUpdate3 ANOP
  272. *
  273.             phy                         ;prepare to redraw all contents
  274.             phx
  275.             _BeginUpdate
  276. *
  277.             pushlong DialogWindowPtr    ;recreate all control handles
  278.             _KillControls               ;because port/land were deleted
  279.             pha
  280.             pha
  281.             pushlong DialogWindowPtr
  282.             pushword #3
  283.             pushlong #StyleControlTemp
  284.             _NewControl2
  285.             pla
  286.             pla
  287. *
  288.             jsr    RedrawDialog         ;do redrawing
  289. *
  290.             pha                         ;dump port/land so won't track
  291.             pha
  292.             pushlong DialogWindowPtr
  293.             pushlong #orientationPortraitItemID
  294.             _GetCtlHandleFromID
  295.             _DisposeControl
  296.             pha
  297.             pha
  298.             pushlong DialogWindowPtr
  299.             pushlong #orientationLandscapeItemID
  300.             _GetCtlHandleFromID
  301.             _DisposeControl
  302. *               
  303.             lda    CoStOrientationState ;do inverting of port/land
  304.             cmp    #1
  305.             beq    CoStRedrawIItsLand
  306. CoStRedrawIItsPort pushlong #orientationPortraitRect
  307.             bra    CoStRedrawInvert
  308. CoStRedrawIItsLand pushlong #orientationLandscapeRect
  309. CoStRedrawInvert _InvertRect
  310. *
  311.             pushlong DialogWindowPtr    ;done redrawing all contents
  312.             _EndUpdate
  313. *
  314.             brl    CoStEventLoop        ;go handle another event
  315. CoStNotUpdate ANOP
  316.  
  317. *Begin check for our own manual "icon radio buttons":
  318.             cmp    #wInContent          ;mouse down on icon(?) event yet?
  319.             beq    CoStCheckIconButtons ;yes, so check icon buttons
  320.             brl    CoStCheckOtherCtrl   ;no, check other events
  321.  
  322. *Do our "icon radio buttons" entirely ourselves:
  323. CoStCheckIconButtons pushlong #DialogWhere   ;modify  coordinates...
  324.             _GlobalToLocal              ;... to window coordinates
  325.             pha                         ;result space
  326.             pushlong #DialogWhere       ;check our point...
  327.             pushlong #orientationPortraitRect     ;...against portrait icon
  328.             _PtInRect
  329.             pla
  330.             beq    CoStNotPortrait      ;it's not in portrait icon
  331.             lda    CoStOrientationState ;mouse is down in portrait
  332.             bne    CoStFlipOrientation  ;we were in landscape, flip 'em
  333.             brl    CoStEventLoop        ;forget it, already in portrait
  334. *
  335. CoStNotPortrait pha                     ;result space
  336.             pushlong #DialogWhere       ;check our point...
  337.             pushlong #orientationLandscapeRect    ;...against landscape icon
  338.             _PtInRect
  339.             pla
  340.             beq    CoStCheckOtherCtrl   ;it's not in landscape icon
  341.             lda    CoStOrientationState ;mouse is now down in landscape
  342.             beq    CoStFlipOrientation
  343.             brl    CoStEventLoop
  344. CoStFlipOrientation eor #1                    ;flip bit
  345.             sta    CoStOrientationState       ;remember it
  346.             pushlong #orientationPortraitRect ;invert both icons, thus moving
  347.             _InvertRect                       ;the highlight to the other one
  348.             pushlong #orientationLandscapeRect
  349.             _InvertRect
  350.             brl    CoStEventLoop               ;were done; go for more
  351.  
  352. *Handle other control events:                           
  353. CoStCheckOtherCtrl cmp #$0021           ;wInControl event yet?
  354.             beq    CoStGotCtrl
  355.             brl    CoStEventLoop        ;...loop until such event
  356. CoStGotCtrl lda    DialogTaskData4      ;get lo order control item ID
  357.  
  358. *Just get out if Cancel selected:
  359.             cmp    #cancelItemID        ;if Cancel, let's exit
  360.             bne    CoStNotCancel
  361.             jsr    FinishDialog         ;dump dialog box
  362.             lda    #0                   ;confirmFlag will be false
  363.             rts
  364.  
  365. *Resume event handling if OK was not selected:
  366. CoStNotCancel cmp  #okItemID            ;if OK, go save stuff & exit
  367.             beq    CoStOkSelected
  368.             brl    CoStEventLoop        ;else resume event handling
  369.  
  370. *Save stuff in print record before leaving if OK selected:
  371. CoStOkSelected lda CoStOrientationState ;do this  first; it's unique
  372.             sta    OptionA
  373.             jsr    SetOrientation
  374. *
  375.             lda    #paperTypeItemID
  376.             jsr    GetControlValue
  377.             sec
  378.             sbc    #paperTypeUSALtrItemID ;normalize
  379.             sta    OptionA
  380.             jsr    SetPaper
  381. *
  382.             lda    #reductionItemID
  383.             jsr    GetControlValue
  384.             sec
  385.             sbc    #reductionFullSizeItemID  ;normalize
  386.             sta    OptionA
  387.             jsr    SetReduction
  388. *
  389.             lda    #effectsNoGapsItemID
  390.             jsr    GetControlValue
  391.             sta    OptionA
  392.             jsr    SetPageGap
  393. *
  394.             lda    #effectsCondensedItemID
  395.             jsr    GetControlValue
  396.             sta    OptionA
  397.             jsr    SetVSize
  398.  
  399. *Now get rid of box, validate print record because it changed, and exit with
  400. *ACC set:
  401.             jsr    FinishDialog         ;dump dialog box
  402.             jsr    CalcMetrics          ;make sure it's self-consistent
  403.             lda    #1                   ;confirmFlag will be true
  404.             rts
  405.  
  406. *DATA: Keeping track of the "icon radio buttons" which we are doing ourselves:
  407.  
  408. CoStOrientationState dc i2'0'           ;0=portrait; 1=landscape
  409.  
  410.             END
  411.  
  412. *
  413. *CONDUCTJOBDIALOG: Does dialogs/TaskMaster, metrics/change print record,
  414. *checks installed options by communicating to printer.  If error happens
  415. *during communication, returns with tool error set.
  416. *On exit, ACC is set if OK was selected:
  417. *
  418.  
  419. ConductJobDialog   START
  420.             USING  PicterData
  421.  
  422.             jsr GetOutputPortName  ;fill-in "printer/port" string
  423.  
  424. *Make dialogdata contain values from print record EXCEPT page range and
  425. *number of copies:
  426.  
  427.             jsr    GetQuality
  428.             clc
  429.             adc    #printQualityStandardItemID
  430.             sta    printQualityInitValue
  431. *                           
  432.             jsr    GetColor
  433.             php
  434.             ldy    #chromaMonochromeItemID
  435.             plp
  436.             beq    CoJoSetIt2
  437.             iny
  438. CoJoSetIt2  sty    chromaInitValue
  439. *
  440.             jsr    GetFeed
  441.             php
  442.             ldy    #pageFeedManualItemID
  443.             plp
  444.             beq    CoJoSetIt3
  445.             iny
  446. CoJoSetIt3  sty    pageFeedInitValue
  447. ;
  448. ; Here is where you should check the printer for options (like color
  449. ; ribbons) and disable items in the dialog that aren't available.
  450. ;
  451.  
  452. *Set default page range and copies just like in what PrDefault would do:
  453.             lda    #1
  454.             sta    OptionA
  455.             lda    #32767
  456.             sta    OptionB
  457.             jsr    SetPageRange
  458.             jsr    SetCopies
  459.  
  460. *Now set up the LE boxes, and set the All/From-To radio button states:
  461.  
  462.             shortm
  463.             stz    pagesFromBoxString   ;reset from/to LE box lengths to zero
  464.             stz    pagesToBoxString
  465.             lda    #'1'                 ;but put "1" in #-of-copies LE box
  466.             sta    copiesBoxString+1
  467.             lda    #1
  468.             sta    copiesBoxString
  469.             sta    pagesAllInitValue    ;set default "All" pages radio button
  470.             stz    pagesRangeInitValue
  471.             longm
  472.  
  473. *Now draw the window with all the controls:
  474.             lda    #JobControlTemp      ;get address of control template
  475.             sta    ParamLongA+0
  476.             lda    #JobControlTemp|-16
  477.             sta    ParamLongA+2
  478.             jsr    StartDialog          ;draw window with controls
  479.  
  480. *Setup TaskMask not to handle keyboard events:
  481.             lda    #DialogTaskMaskNoKeys|-16 ;need change hi word only...
  482.             sta    DialogTaskMask+2
  483.  
  484. *Get LineEdit (LE) handle ready for Copies item and then go to event loop.
  485. *ParamLongA has LE handle:
  486.  
  487.             pha
  488.             pha
  489.             pushlong DialogWindowPtr
  490.             pushlong #copiesBoxItemID
  491.             _GetCtlHandleFromID
  492.             pulllong ParamLongA         ;"Copies" item's handle in ParamLongA
  493.             brl    CoJoSetLEAndGotoLoop ;go get LE hdl and go to event loop
  494.  
  495. *Event loop which gets mouseclicks/keys and controls animation:
  496. CoJoEventLoop pushlong ParamLongA       ;blink a cursor
  497.             _LEIdle
  498. CoJoDoTasks pha                         ;result space
  499.             pushword #$FFFF             ;event mask
  500.             pushlong #DialogTaskRecord  ;where to stuff event data
  501.             _TaskMaster                 ;do events
  502.             pla
  503.  
  504. *Do redrawing of controls for update event, if necessary:
  505.             cmp    #6                   ;update event?
  506.             bne    CoJoNotUpdate
  507.             ldx    DialogWindowPtr+0    ;check if it's our window
  508.             cpx    DialogTaskData+0
  509.             bne    CoJoNotUpdate
  510.             ldy    DialogWindowPtr+2
  511.             cpy    DialogTaskData+2
  512.             bne    CoJoNotUpdate
  513.             phy                         ;redraw all contents
  514.             phx
  515.             _BeginUpdate
  516.             jsr    RedrawDialog
  517.             pushlong DialogWindowPtr
  518.             _EndUpdate
  519.             bra    CoJoEventLoop
  520. CoJoNotUpdate ANOP
  521.  
  522. *Check for mousedown in a control or if a key was hit:
  523.             cmp    #$0021               ;wInControl?
  524.             bne    CoJoNotInCtrl
  525.             brl    CoJoCheckCtrls
  526. CoJoNotInCtrl cmp  #$0003               ;keyDownEvt?
  527.             bne    CoJoEventLoop
  528.  
  529. *A key has been hit; do OK/Cancel hilite ourselves if selected because not
  530. *going thru taskmaster:
  531.             lda    DialogMessage
  532.             cmp    #okItemKeyEquiv
  533.             bne    CoJoNotKeyOk
  534.             pha
  535.             pha
  536.             pushlong DialogWindowPtr
  537.             pushlong #okItemID
  538.             _GetCtlHandleFromID
  539.             pulllong ParamLongA         ;clobber this, but we're out anyway
  540.             pushword #1
  541.             pushlong ParamLongA
  542.             _HiliteControl
  543.             pushword #0
  544.             pushlong ParamLongA
  545.             _HiliteControl
  546.             brl    CoJoOk
  547. CoJoNotKeyOk cmp   #cancelItemKeyEquiv
  548.             bne    CoJoNotKeyCancel
  549.             pha
  550.             pha
  551.             pushlong DialogWindowPtr
  552.             pushlong #cancelItemID
  553.             _GetCtlHandleFromID
  554.             pulllong ParamLongA         ;clobber this, but we're out anyway
  555.             pushword #1
  556.             pushlong ParamLongA
  557.             _HiliteControl
  558.             pushword #0
  559.             pushlong ParamLongA
  560.             _HiliteControl
  561.             brl    CoJoCancel
  562. CoJoNotKeyCancel ANOP
  563.  
  564. *If TAB and proper LEHandle, try to move insertion point to another box:
  565.             cmp    #9                   ;TAB key?
  566.             bne    CoJoNotKeyTab        ;not TAB key
  567.             pushlong ParamLongA         ;save old LE handle on stack
  568. *                           
  569.             pha                         ;get "From" ctl hdl in ParamLongA
  570.             pha
  571.             pushlong DialogWindowPtr
  572.             pushlong #pagesFromBoxItemID
  573.             _GetCtlHandleFromID
  574.             pulllong ParamLongA
  575. *       
  576.             lda    [ParamLongA]         ;cmp to see if old LEH == "From" LEH
  577.             tax
  578.             ldy    #2
  579.             lda    [ParamLongA],y
  580.             sta    ParamLongA+2
  581.             stx    ParamLongA
  582.             ldy    #octlData            ;offset into ctrl rec for LE handle
  583.             lda    [ParamLongA],y       ;lo order word of LE handle
  584.             cmp    1,s                  ;cmp to current LE handle lo
  585.             bne    CoJoNotKeyTabLEH
  586.             iny
  587.             iny
  588.             lda    [ParamLongA],y       ;hi order word of LE handle
  589.             cmp    3,s                  ;cmp to current LE handle hi
  590.             bne    CoJoNotKeyTabLEH
  591. *
  592.             pla                         ;yes, in "From" so yank old LE handle
  593.             pla
  594. *
  595.             pha                         ;and make "To" box the active one
  596.             pha
  597.             pushlong DialogWindowPtr
  598.             pushlong #pagesToBoxItemID
  599.             _GetCtlHandleFromID
  600.             pulllong ParamLongA         ;get "To" ctl hdl in ParamLongA
  601.             pushlong ParamLongA         ;do screen animation
  602.             _MakeThisCtlTarget
  603.             brl    CoJoSetLEAndGotoLoop  ;get LE hdl from ctl hdl and loop
  604. *
  605. CoJoNotKeyTabLEH pulllong ParamLongA    ;didn't  restore old LE handle
  606. CoJoNotKeyTab ANOP
  607.  
  608. *Not OK/Cancel/TAB, so if we have LEHandle, filter out '0'..'9'/LE cmd keys
  609. *and call LEKey:
  610.             lda    DialogMessage        ;look at keystroke ascii code
  611.             shortmx
  612.             ldy    #15
  613. CoJoCheckKeyLoop cmp CoJoLEKeyTable,y   ;is it a key we should handle?
  614.             beq    CoJoLEKey
  615.             dey
  616.             bpl    CoJoCheckKeyLoop
  617.             longmx
  618.             brl    CoJoEventLoop
  619. CoJoLEKeyTable dc  i1'8,21,127'
  620.              dc    i1'6,24,25'
  621.              dc    c'0123456789'
  622. CoJoLEKey   longmx
  623.             pushword DialogMessage
  624.             pushword DialogModifiers
  625.             pushlong ParamLongA
  626.             _LEKey
  627.             brl    CoJoEventLoop
  628.  
  629. *Check if any new LE text boxes were selected; also change All/From-To radio
  630. *buttons:
  631. CoJoCheckCtrls lda DialogTaskData4      ;get lo order control item ID
  632.             cmp    #pagesFromBoxItemID
  633.             beq    CoJoFromToBox
  634. CoJoNotFromBox cmp #pagesToBoxItemID
  635.             bne    CoJoNotToBox
  636. CoJoFromToBox pushword #0               ;switch All/From-To radio button
  637.             pha
  638.             pha
  639.             pushlong DialogWindowPtr
  640.             pushlong #pagesAllItemID
  641.             _GetCtlHandleFromID
  642.             _SetCtlValue                ;turn "All" radio button off
  643.             pushword #1
  644.             pha
  645.             pha
  646.             pushlong DialogWindowPtr
  647.             pushlong #pagesRangeItemID
  648.             _GetCtlHandleFromID
  649.             _SetCtlValue                ;turn the other radio button on
  650.             bra    CoJoItsBox
  651. CoJoNotToBox cmp   #copiesBoxItemID
  652.             bne    CoJoNoLEBoxes
  653.  
  654. *We selected a box; get its LE handle:
  655. CoJoItsBox  lda    DialogTaskData2+0    ;get handle to control record
  656.             sta    ParamLongA+0         ;and drop into next section below
  657.             lda    DialogTaskData2+2
  658.             sta    ParamLongA+2
  659.  
  660. *Get LE handle from ctl handle and then go to event loop:
  661. CoJoSetLEAndGotoLoop lda [ParamLongA]   ;this section transforms the control
  662.             tax                         ;handle of a LE item into a valid
  663.             ldy    #2                   ;LE handle for that item
  664.             lda    [ParamLongA],y
  665.             sta    ParamLongA+2
  666.             stx    ParamLongA+0
  667.             ldy    #octlData            ;offset into ctrl rec for LE handle
  668.             lda    [ParamLongA],y       ;lo order word of LE handle
  669.             tax
  670.             iny
  671.             iny
  672.             lda    [ParamLongA],y       ;hi order word of LE handle
  673.             sta    ParamLongA+2
  674.             stx    ParamLongA+0         ;ParamLongA now has LE handle
  675.             brl    CoJoEventLoop
  676.  
  677. *If no boxes were clicked, since we got wInControl, check for other
  678. *possibilities:
  679. CoJoNoLEBoxes ANOP
  680.  
  681. *Exit without affecting print record if Cancel select:
  682.             cmp    #cancelItemID
  683.             bne    CoJoNotCancel
  684. CoJoCancel  jsr    FinishDialog            ;dump dialog box
  685.             lda    #0                      ;confirmFlag will be false
  686.             rts
  687.  
  688. *If OK select, save data in print record; else resume event handling:
  689. CoJoNotCancel cmp  #okItemID
  690.             beq    CoJoOk
  691.             brl    CoJoEventLoop
  692. *
  693. CoJoOk      lda    #printQualityItemID
  694.             jsr    GetControlValue
  695.             sec
  696.             sbc    #printQualityStandardItemID ;normalize
  697.             sta    OptionA
  698.             jsr    SetQuality
  699. *
  700.             lda    #chromaItemID
  701.             jsr    GetControlValue
  702.             sec
  703.             sbc    #chromaMonochromeItemID     ;normalize
  704.             sta    OptionA
  705.             jsr    SetColor
  706. *
  707.             lda    #pageFeedItemID
  708.             jsr    GetControlValue
  709.             sec
  710.             sbc    #pageFeedManualItemID     ;normalize
  711.             sta    OptionA
  712.             jsr    SetFeed
  713.  
  714. *Initially assume default values for both parts of the page range:
  715.             lda    #1
  716.             sta    OptionA
  717.             lda    #32767
  718.             sta    OptionB
  719.  
  720. *If "All" page range option selected, skip the following few sections:
  721.             lda    #pagesAllItemID
  722.             jsr    GetControlValue
  723.             cmp    #1
  724.             beq    CoJoSetPageRange
  725.  
  726. *"All" not selected, so get each part of the page range only if nonzero.
  727. *Pin on upper limit:
  728.             lda    #pagesFromBoxItemID  ;convert "From" string to number
  729.             jsr    GetBoxValue
  730.             cmp    #0                   ;if zero, keep our default
  731.             beq    CoJoDontConsiderPgRngA
  732.             cmp    #32768               ;pin to largest value and store
  733.             bcc    CoJoConsiderPgRngA
  734.             lda    #32767
  735. CoJoConsiderPgRngA sta OptionA
  736. CoJoDontConsiderPgRngA ANOP
  737.             lda    #pagesToBoxItemID    ;convert "To" string to number
  738.             jsr    GetBoxValue
  739.             cmp    #0                   ;if zero, keep our default
  740.             beq    CoJoDontConsiderPgRngB
  741.             cmp    #32768               ;pin to largest value and store
  742.             bcc    CoJoConsiderPgRngB
  743.             lda    #32767
  744. CoJoConsiderPgRngB sta OptionB
  745. CoJoDontConsiderPgRngB ANOP
  746.  
  747. *With first page in OptionA and last page in OptionB, see if backwards:
  748.             lda    OptionB
  749.             cmp    OptionA              ;check page range
  750.             bcs    CoJoPageRangeNotBackwards ;at it's least not backwards
  751.             ldx    OptionA              ;else exchange A,B...
  752.             sta    OptionA
  753.             stx    OptionB
  754. CoJoPageRangeNotBackwards ANOP
  755.  
  756. *With sane values for first page in OptionA and last page in OptionB, set
  757. *the page range:
  758. CoJoSetPageRange jsr SetPageRange
  759.  
  760. *Set number of copies, pinning to largest possible value and ensuring nonzero:
  761.             lda    #copiesBoxItemID     ;convert "Copies" str to number
  762.             jsr    GetBoxValue
  763.             cmp    #32768               ;pin within range 1..32767...
  764.             bcc    CoJoNoPinCopies1
  765.             lda    #32767
  766. CoJoNoPinCopies1 cmp #0
  767.             bne    CoJoNoPinCopies2
  768.             lda    #1
  769. CoJoNoPinCopies2 sta OptionA
  770.             jsr    SetCopies
  771.  
  772. *Dump dialog box, validate print record because it changed, and exit with
  773. *ACC set:
  774.             jsr    FinishDialog         ;dump the box
  775.             jsr    CalcMetrics
  776.             lda    #1                   ;confirmFlag will be true
  777.             rts
  778.  
  779.             END
  780.  
  781. *
  782. *SUBROUTINES: Used by routines above to perform various setup/shutdown and
  783. *repeated tasks:
  784. *
  785.  
  786. *
  787. *STARTDIALOG: Draws our standard dialog window; fills with control list
  788. *given by "ParamLongA":
  789. *
  790. StartDialog START
  791.             USING  PicterData
  792.  
  793.             pha                         ;result space for old grafport
  794.             pha
  795.             _GetPort
  796.             pulllong OldGrafPortPtr     ;save old grafport pointer
  797.  
  798. *Modify coordinates of dialog window to suit 320/640 mode:
  799.             lda    WindowCoordX2
  800.             sec
  801.             sbc    WindowCoordX1        ;calc box size (silly at runtime)
  802.             sta    ParamWordA           ;save size
  803.             pha                         ;result space for scb
  804.             _GetMasterSCB
  805.             pla
  806.             ldx    #640                 ;assume 640 mode for a sec
  807.             and    #$80                 ;look at mode bit (1=640, 0=320)
  808.             bne    StDiMode640
  809.             ldx    #320                 ;change assumption made above
  810. StDiMode640 txa
  811.             sec
  812.             sbc    ParamWordA           ;a-reg now has [320|640] - (X2-X1)
  813.             lsr    a                    ;divide by two
  814.             sta    WindowCoordX1        ;this is left coordinate of box
  815.             clc
  816.             adc    ParamWordA           ;maintain proper box size
  817.             sta    WindowCoordX2        ;this is right coordinate of box
  818.  
  819. *Draw the window on the screen and set as current port:
  820.             pushlong #0                 ;result space for window grafportptr
  821.             pushlong #WindowTemp
  822.             _NewWindow                  ;draw window from template
  823.             lda    1,s                  ;keep on stack for SetPort only
  824.             sta    DialogWindowPtr+0    ;and also save it away
  825.             lda    3,s
  826.             sta    DialogWindowPtr+2
  827.             _SetPort                    ;set our window as current port
  828.  
  829. *Create (but don't draw yet) the controls in the window using the given
  830. *control template:
  831.             pushlong #0                 ;result space
  832.             pushlong DialogWindowPtr    ;window's grafport to draw in
  833.             pushword #3                 ;ptrToPtr input reference
  834.             pushlong ParamLongA         ;get desired control template
  835.             _NewControl2
  836.             pla                         ;we don't need these zeros
  837.             pla
  838.  
  839. *Draw the controls and exit:
  840.             jsr    RedrawDialog
  841.             rts
  842.  
  843.             END
  844.  
  845. *
  846. *REDRAWDIALOG: Call this routine to redraw contents of window (during update
  847. *event, for example):
  848. *
  849. RedrawDialog START
  850.              USING PicterData
  851.  
  852.              pushlong DialogWindowPtr
  853.             _DrawControls               ;fill window with controls...
  854.             pushword #1                 ;draw horizontal adornment line...
  855.             pushword #2
  856.             _SetPenSize
  857.             pushword #WindowLineX1
  858.             pushword #WindowLineY
  859.             _MoveTo
  860.             pushword #WindowLineX2
  861.             pushword #WindowLineY
  862.             _LineTo
  863.             _InitCursor                 ;ensure arrow cursor...
  864.             rts
  865.  
  866.             END
  867.  
  868. *
  869. *FINISHDIALOG: Call this routine when done with dialog; erases
  870. *window/controls and releases memory:
  871. *
  872. FinishDialog START
  873.             USING  PicterData
  874.  
  875.             pushlong DialogWindowPtr
  876.             _CloseWindow                ;erase window and dispose memory
  877.             pushlong OldGrafPortPtr     ;get old port pointer
  878.             _SetPort                    ;restore it
  879.             rts
  880.  
  881.             END
  882.  
  883. *
  884. *GETOUTPUTPORTNAME: Routine which sets up "XXX" part in "PICTER/XXX" in
  885. *dialog data:
  886. *
  887. GetOutputPortName START
  888.             USING  PicterData
  889.  
  890.             pha
  891.             pha
  892.             ldx    #$2913               ;get pointer to str w/ port name
  893.             jsl    $E10000              ;_PMGetPortName
  894.             pulllong ParamLongA
  895.             shortmx
  896.             lda    [ParamLongA]
  897.             tay
  898.             clc
  899.             adc    #PortTitleLenOrig    ;store correct length of full...
  900.             sta    PortTitleLen         ;...port title...
  901. GePoNaStrCpy lda   [ParamLongA],y       ;and  PRINTER, etc., string
  902.             sta    PortTitleStr-1,y
  903.             dey
  904.             bne    GePoNaStrCpy
  905.             longm
  906.             longx
  907.             rts
  908.  
  909.             END
  910.  
  911. *
  912. *DIMPOPUPITEM: Dims pop-up menu item. Menu_ctl_ID -> ParamWordA,
  913. *Menu_ctl_item_ID -> ParamWordB:
  914. *
  915.  
  916. ;
  917. ; This isn't actually used by the picter driver, but it's handy to
  918. ; have around...
  919.  
  920. DimPopUpItem START
  921.             USING  PicterData
  922.  
  923.             pha                        ;save menu bar hdl on stack...
  924.             pha
  925.             _GetMenuBar
  926.             pha                         ;result space...
  927.             pha                         ;...for GetCtlHandleFromID
  928.             pushlong DialogWindowPtr    ;pass window pointer
  929.             pushword #0                 ;pass hi order word of ID
  930.             pushword ParamWordA         ;pass lo order word of ID
  931.             _GetCtlHandleFromID         ;get pop-up control handle...
  932.             _SetMenuBar                 ;...and set as current menu bar
  933.             pushword ParamWordB         ;now that menu mgr knows about
  934.             _DisableMItem               ;our control, disable item
  935.             _SetMenuBar                 ;...restore menu bar from stack
  936.             rts
  937.  
  938.             END
  939.  
  940. *
  941. *GETCONTROLVALUE: Obtains control state. Put ID lo order word -> ACC; on
  942. *exit, ACC -> control value:
  943. *
  944. GetControlValue START
  945.             USING PicterData
  946.  
  947.             sta ParamWordA          ;save  use in a second
  948.             pha                         ;result space for GetCtlValue
  949.             pha                         ;result space...
  950.             pha                         ;...for GetCtlHandleFromID
  951.             pushlong DialogWindowPtr    ;pass window pointer
  952.             pushword #0                 ;pass hi order word of ID
  953.             pushword ParamWordA         ;pass lo order word of ID
  954.             _GetCtlHandleFromID         ;get handle
  955.             _GetCtlValue                ;use handle to get value
  956.             pla                         ;leave value in accumulator
  957.             rts
  958.             END
  959.  
  960. *
  961. *GETBOXVALUE: Gets integer from LineEdit control.  Put ID lo order -> ACC;
  962. *on exit, ACC -> integer:
  963. *
  964. GetBoxValue START
  965.             USING  PicterData
  966.  
  967.             sta    ParamWordA           ;save for use in a second
  968.             pha                         ;result space for GetCtlValue...
  969.             pha                         ;...result space
  970.             pushlong DialogWindowPtr    ;pass window pointer
  971.             pushword #0                 ;pass hi order word of ID
  972.             pushword ParamWordA         ;pass lo order word of ID
  973.             _GetCtlHandleFromID         ;get handle to control record
  974.             pulllong ParamLongA         ;get it off stack into dp
  975.             lda    [ParamLongA]         ;dereference the handle
  976.             tax
  977.             ldy    #2
  978.             lda    [ParamLongA],y
  979.             sta    ParamLongA+2
  980.             stx    ParamLongA           ;ParamLongA is now a pointer
  981.             ldy    #octlData            ;offset ctrl rec for LE handle
  982.             lda    [ParamLongA],y
  983.             tax
  984.             iny
  985.             iny
  986.             lda    [ParamLongA],y       ;a,x now has LE handle
  987.             pha                         ;result space for LEGetTextHand
  988.             pha                         ;result space for LEGetTextHand
  989.             pha                         ;hi LE handle for LEGetTextHand
  990.             phx                         ;lo LE handle for LEGetTextHand
  991.             pha                         ;result space for LEGetTextLen
  992.             pha                         ;hi LE handle for LEGetTextLen
  993.             phx                         ;lo LE handle for LEGetTextLen
  994.             _LEGetTextLen               ;get length of our text line
  995.             pullword ParamWordA         ;save length for use in a sec
  996.             _LEGetTextHand              ;get handle to our text line
  997.             pulllong ParamLongA         ;get it off stack into dp
  998.             lda    [ParamLongA]         ;dereference the handle again
  999.             tax
  1000.             ldy    #2
  1001.             lda    [ParamLongA],y
  1002.             sta    ParamLongA+2
  1003.             stx    ParamLongA           ;we now have pointer to string!
  1004.             pha                         ;result space
  1005.             pushlong ParamLongA         ;pass the pointer
  1006.             pushword ParamWordA         ;pass string length
  1007.             pushword #0                 ;pass that this is unsigned
  1008.             _Dec2Int                    ;convert ascii to word
  1009.             pla                         ;get result in accumulator
  1010.             rts
  1011.  
  1012.             END
  1013.